﻿// ———————————————————————–
// <copyright file="ResourcePrimaryStatusCode.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// ResourcePrimaryStatusCode.cs:
// Simple interface for composable objects that can be written inline to XML
// Project: IC.NET - EDXL Library
//
// Language:    C#, .NET 4.0
// Platform:    Windows 7, VS 2012
// Author:      Jim Cronin MITRE Bedford

/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using System;

namespace EDXLSharp.NIEMCADLib
{
  public enum ResourcePrimaryStatusCode
  {
    /// <summary>
    /// Emergency Unit stutus is unknown.
    /// This should only be used when there's a parsing error.
    /// </summary>
    Unknown,
    /// <summary>
    /// Emergency Unit is available for Dispatch
    /// </summary>
    Available,
    /// <summary>
    /// Emergency Unit is assigned to an activity, but is available for dispatch or reassignment
    /// </summary>
    ConditionallyAvailable,
    /// <summary>
    /// Emergency Unit is not available for Dispatch and cannot be assigned to a call
    /// </summary>
    NotAvailable
  }

  public static class ResourcePrimaryStatusCodeHelper
  {
    /// <summary>
    /// Gets the text to be written to XML for this status code
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    public static string GetText(this ResourcePrimaryStatusCode code)
    {
      switch (code)
      {
        case ResourcePrimaryStatusCode.Unknown:
          return "UNKNOWN";
        case ResourcePrimaryStatusCode.Available:
          return "AVAILABLE";
        case ResourcePrimaryStatusCode.ConditionallyAvailable:
          return "CONDITIONALLY AVAILABLE";
        case ResourcePrimaryStatusCode.NotAvailable:
          return "NOT AVAILABLE";
        default:
          throw new ArgumentOutOfRangeException("Not a valid/known value for ResourcePrimaryStatusCode");
      }
    }

    /// <summary>
    /// Converts a text value to a ResourcePrimaryStatusCode
    ///  - First checks for the XML text of each code
    ///  - Lastly just calls Enum.Parse
    /// </summary>
    /// <param name="value">String to parse</param>
    /// <returns>ResourcePrimaryStatusCode described by value</returns>
    /// <exception cref="System.ArgumentNullException">Thrown if value is null</exception>
    /// <exception cref="System.ArgumentException">Thrown if value is empty or whitespace</exception>
    /// <exception cref="System.OverflowException">Thrown if value does not represent a ResourcePrimaryStatusCode</exception>
    public static ResourcePrimaryStatusCode GetCode(string value)
    {
      switch (value)
      {
        case "UNKNOWN":
          return ResourcePrimaryStatusCode.Unknown;
        case "AVAILABLE":
          return ResourcePrimaryStatusCode.Available;
        case "CONDITIONALLY AVAILABLE":
          return ResourcePrimaryStatusCode.ConditionallyAvailable;
        case "NOT AVAILABLE":
          return ResourcePrimaryStatusCode.NotAvailable;
        default:
          //TODO: ResourcePrimaryStatusCode.GetCode - Test to confirm invalid values don't give us a valid enum value
          return (ResourcePrimaryStatusCode)Enum.Parse(typeof(ResourcePrimaryStatusCode), value);
      }
    }
  }
}